﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Hybrid
{
    class Background
    {
        private Image privateImage = Image.FromFile(Application.StartupPath + "\\Images\\Backgrounds\\background1.jpg");
        private int privateIndex = 1;
        private int privateY = 0;
        private int privateSpeed = 3;
        private int privateMaxHeight = 570;
        private int privateMaxWidth = 730;
        private Leveling privateLevel;
        private int privateMapDistance = 0;

        public Background()
        {
            
        }

        public void SetLevel(Leveling level)
        {
            privateLevel = level;
        }

        public Image Image
        {
            get
            {
                return privateImage;
            }
        }

        public void Next()
        {
            privateIndex++;
            privateImage = Image.FromFile(Application.StartupPath + "\\Images\\Backgrounds\\background" + privateIndex + ".jpg");
        }


        public void GoToIndex(int index)
        {
            privateImage = Image.FromFile(Application.StartupPath + "\\Images\\Backgrounds\\background" + index + ".jpg");
        }

        public void DrawBackground(Graphics g)
        {
            if (privateY >= privateMaxHeight)
            {
                privateY = 0;
                privateMapDistance++;
                if (privateMapDistance == 10)
                {
                    UpLevel();
                    privateMapDistance = 0;
                }
            }
            privateY += privateSpeed;
            g.DrawImage(privateImage, 0, privateY, privateMaxWidth, privateMaxHeight);
            g.DrawImage(privateImage, 0, privateY - privateMaxHeight, privateMaxWidth, privateImage.Height);
        }

        private void UpLevel()
        {
            privateLevel.NextLevel();
        }
    }
}
